using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_CREATURE_QUERY_RESPONSE_DEF : DefinitionBase
    {
        public override bool Process()
        {
            creature_template template = GetCreatureTemplate();
            GlobalCache.AddCreatureTemplateSum(template, ClientBuild);
             
            return Validate();
        }

        public creature_template GetCreatureTemplate()
        {
            ResetPosition();
            creature_template template = new creature_template();
 
            template.entry = ReadUInt32();
            template.name = ReadString();
            ReadString();
            ReadString();
            ReadString();
            template.subname = ReadString();
            if (ClientBuild >= 7561)
            {
                template.iconname = ReadString();// "Directions" for guard, string unk 2.3.0.7561
            }
            template.flags_extra = ReadUInt32();// flags          wdbFeild7=wad flags1
            template.type = (byte)ReadUInt32();
            template.family = (sbyte)ReadUInt32();// family         wdbFeild9
            template.rank = (byte)ReadUInt32();// rank           wdbFeild10

            if (ClientBuild < 9183)
            {
                ReadUInt32();// unknown        wdbFeild11
            }

            if (ClientBuild >= 9767)
            {
                template.killcredit1 = ReadUInt32();                  // new in 3.1, kill credit
                template.killcredit2 = ReadUInt32();                  // new in 3.1, kill credit
            }

            if (ClientBuild < 10314)
            {
                ReadUInt32();//template.spelldataid Id from CreatureSpellData.dbc    wdbFeild12
            }

            template.modelid_a = ReadUInt32();// modelid_male1
            template.modelid_h = ReadUInt32();// modelid_female1 ?
            template.modelid_a2 = ReadUInt32();// modelid_male2 ?
            template.modelid_h2 = ReadUInt32();// modelid_femmale2 ?
            template.unk16 = ReadSingle();// unk
            template.unk17 = ReadSingle();// unk
            template.racialleader = ReadByte();

            if (ClientBuild > 9551)
            {
                template.questitem1 = ReadUInt32();
                template.questitem2 = ReadUInt32();
                template.questitem3 = ReadUInt32();
                template.questitem4 = ReadUInt32();
 
                if (ClientBuild >= 10314)
                {
                    template.questitem5 = ReadUInt32();
                    template.questitem6 = ReadUInt32();
                }
            }

            if (ClientBuild > 9947)
            {
                template.movementid = ReadUInt32();
            }

            return template;
        }
    }
}
